﻿@{
    Layout = null;
}

<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>生产岗位</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link href="~/Content/X-admin/css/font.css" rel="stylesheet" />
    <script src="~/Content/X-admin/lib/layui/layui.js"></script>
    <link href="~/Content/X-admin/css/xadmin.css" rel="stylesheet" />
    <script src="~/Content/X-admin/js/jquery.min.js"></script>
    <script src="~/Content/X-admin/js/xadmin.js"></script>
    <script src="~/Content/Scripts/System/Common.js"></script>
    <script src="~/Content/Scripts/System/systemFrame.js"></script>
</head>
<body>
    <span style="margin-top:15px;margin-left:15px">
        <xblock>
            <button class="layui-btn" onclick="submitData()"><i class="layui-icon"></i>提交</button>
            <button class="layui-btn" onclick="closeWin()"><i class="layui-icon">&#x1006;</i>取消</button>
        </xblock>
    </span>
    <div style="margin: 10px; border: 1px solid #dbdbdb;padding:15px">

        <form id="AddForm" class="layui-form layui-col-space5">
            <div class="layui-form-item">
                <label class="layui-form-label">生产工序</label>
                <div class="layui-input-inline">
                    <select id="gxCode" name="gxCode" class="gxCode">
                        <option value="">生产工序</option>
                    </select>

                </div>
                <input type="hidden" name="pCode" id="pCode" />
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">上产岗位</label>
                <div class="layui-input-inline">
                    <select id="gangwei" name="gangwei" class="position">
                        <option value="">选择岗位</option>
                    </select>
                </div>
                <label class="layui-form-label">人数</label>
                <div class="layui-input-inline">
                    <input type="text" id="pCount" name="pCount" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">

                <label class="layui-form-label">占比</label>
                <div class="layui-input-inline">
                    <input type="text" name="zhanbi" autocomplete="off" class="layui-input" id="zhanbi">
                </div>
            </div>
        </form>
        <div class="layui-form-item">
            <button class="layui-btn" onclick="SaveData()"><i class="layui-icon">&#xe639;</i>保存</button>
        </div>
        <div class="layui-card-body layui-table-body layui-table-main">
            <table class="layui-hide" id="list" lay-filter="list"></table>
        </div>
    </div>
</body>
</html>
<script type="text/html" id="barDemo">
        <a title="删除" href="javascript:;" lay-event="del"><i class="layui-icon">&#xe640;</i></a>
 
</script>

<script>
    var tCode = "",gxCode="";
    $(function () {
        tCode = getUrlVariable("dataId");
        gxCode = getUrlVariable("gxCode");
        CommonData('proGx', "gxCode");
        CommonData('scgw', "position");
        if (tCode != "0") {
            $("input[ name='pCode']").val(tCode);
            loadData();
        } else {
            $("input[ name='pCode']").val(dateTimeStr);
        }
        if (gxCode != "") {
            $("#gxCode  option[value='" + gxCode + "'] ").attr("selected", true);
            $("#gxCode").attr("disabled", "disabled").css("background-color", "#EEEEEE;");
        }
        layui.use('form', function () {
            var form = layui.form;
            form.render();
        });
    })

    //加载数据信息
    function loadData() {
        $.ajax({
            url: "../Basis/getPositonByCode",
            type: "post",
            data: { tempCode: tCode },
            success: function (data) {
                if (data.Result) {
                    loadTableData();
                }
            }
        });
    }
    function submitData() {
        tCode = $("input[ name='pCode']").val();
        var gxCode = $("#gxCode option:selected").val(); 
        $.ajax({
            url: "../Basis/SaveProductPosition",
            data: { tempCode: tCode, gxCode: gxCode },
            dataType: "json",
            type: "POST",
            success: function (data) {
                if (data.Result) {
                    var id = $("input[ name='id']").val();
                    var msg = "信息修改成功";
                    if (id == "0" || id == "") {
                        msg = "信息添加成功";
                    }
                    layer.alert(msg, { icon: 6 }, function () {
                        // 获得frame索引
                        var index = parent.layer.getFrameIndex(window.name);
                        //关闭当前frame
                        parent.layer.close(index);
                    });
                } else {
                    layer.msg(data.Message);
                }
            }
        });
    }
    /**
    添加岗位数据
    **/
    function SaveData() {
        var tCode = $("input[ name='pCode']").val();
        var gwName = $("#gangwei").find("option:selected").text();
        $.ajax({
            url: "../Basis/AddProductPosition",
            data: { datas: JSON.stringify(FormToJson("AddForm")), tempCode: tCode, gwName: gwName },
            dataType: "json",
            type: "POST",
            success: function (data) {
                if (data.Result) {
                    layer.msg("添加成功");
                    loadTableData();
                } else {
                    layer.msg(data.Message);
                }
            }
        });
    }

    function loadTableData() {
        layui.use('table', function () {
            var conditon = $("input[ name='pCode']").val();
            var table = layui.table;
            table.render({
                elem: '#list'
            , cols: [[ //标题栏
                { field: 'gwCode', title: '岗位编码', width: 100 }
              , { field: 'gwName', title: '岗位名称', width: 100 }
              , { field: 'pCount', title: '人数', width: 100 }
              , { field: 'zhanbi', title: '占比', width: 120 }
              , { field: 'right', title: '数据操作', toolbar: '#barDemo', width: 90, fixed: 'right' }
            ]], done: function (res, curr, count) {
    
            }
            , url: "../Basis/GetDataList?dataType=tList&condition=" + conditon
            , skin: 'row' //表格风格
            , even: true
            , page: false //是否显示分页
            , limits: [15, 20, 30]
            , limit: 10 //每页默认显示的数量
            });
            //监听工具条
            table.on('tool(list)', function (obj) {
                var data = obj.data;
                if (obj.event === 'del') {
                    layer.confirm('确认要删除该数据？', function (index) {
                        var info = DelData(data.id, conditon, data.gwCode);
                        if (info.Result) {
                            obj.del();
                        } else {
                            layer.msg(info.Message);
                        }
                        layer.close(index);
                    });
                }

            });

        });
    }
    function DelData(dataId,pCode,gwCode) {
        var info = undefined;
        $.ajax({
            url: "../Basis/DelPositionByCode",
            data: { dataId: dataId, pCode: pCode, gwCode: gwCode },
            dataType: "json",
            type: "POST",
            async: false,
            success: function (data) {
                info = data;
            }
        });
        return info;
    }
</script>